<template>
	<view>
		<view class="bac_f">
			<u-tabs
				lineWidth="30"
				lineColor="#F14537"
				:current="current"
				@click="tabClick"
				:list="tab_list"
				itemStyle="padding-left: 10px; padding-right:10px; height: 42px;"
				:activeStyle="{
					color: '#F14537',
					fontWeight: 'bold',
					transform: 'scale(1.05)'
				}"
				:inactiveStyle="{
					color: '#999999',
					transform: 'scale(1)'
				}"
			></u-tabs>
		</view>
		<view class="bac_f ml24 mr24 padding30 mt24" v-for="(item,index) in  order_list" :key="index">
			<view class="dis_flex">
				<view class="tf_999 fz24">
					订单编号：{{item.order_no}}
				</view>
				<view class="fz24 tf_4537">
					{{item.order_status==1 ? '已取消' : item.order_status==2 ? '待支付':item.order_status==3 ? '待派单' : item.order_status==4 ? '待上门' : item.order_status==5 ? '服务中' : '已完成'}}
				</view>
			</view>
			<view class="dis_f mt20" @click="goOrderDetail(item)">
				<view class="df">
					<image class="radius12" style="width: 128rpx;height: 128rpx;" :src="item.image" mode="aspectFill"></image>
					<view class="ml24">
						<view class="dis_f">
							<view class="fz26 fw" style="max-width: 350rpx;">
								{{item.name}}
							</view>
						</view>
						<view class="dis_f fz24 mt10 tf_999">
							<view class="">
								预约时间
							</view>
							<view class="ml20 tf_666">
								{{item.reserve_time}}
							</view>
						</view>
						<view class="dis_f fz24 mt10 tf_999">
							<view class="">
								支付金额 
							</view>
							<view class="ml20 tf_666">
								¥{{item.price}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="df je mt24">
				<view v-if="item.order_status==2" class="w152 h56 dis_f jc fz26 tf radius8" style="background-image: linear-gradient(#FE877F,#FE2E27);" @click="goPay(item)">
					去支付
				</view>
				<view v-if="item.order_status==6" class="w152 mr20 h56 dis_f jc border fz26 tf_33 radius8" @click="goAfterSale(item)">
					申请售后
				</view>
				<view v-if="item.order_status==6&&item.is_pingjia!==1" class="w152 h56 dis_f jc border4537 fz26 tf_4537 radius8" @click="goEvaluate(item)">
					去评价
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		orderList,payByOrder
	} from "@/config/api.js";
	export default {
		data() {
			return {
				current:0,
				tab_list: [{ name: '全部' }, { name: '已取消' }, { name: '待支付' }, { name: '待派单' }, { name: '待上门' }, { name: '服务中' },{ name: '已完成' }],
				order_list:[],
			}
		},
		onLoad(option) {
			if(option){
				this.current = option.cur
			}
			this.getOrderInfo()
			uni.$on('refreshData', () => {
				this.getOrderInfo()
			});
		},
		methods: {
			//申请售后
			goAfterSale(e){
				let page_obj = encodeURIComponent(JSON.stringify(e))
				uni.navigateTo({
					url:'../saleAfter/saleAfter?page_obj='+page_obj
				})
			},
			//去支付
			goPay(item){
				payByOrder({order_id:item.order_id}).then(res=>{
					let total = res
					this.getPay(total)
				})
			},
			// 微信支付
			async getPay(total){
				let payCall = await this.common.orderPay(total)
				if(payCall.errMsg == "requestPayment:fail cancel"){
				}else{
					uni.reLaunch({
						url: '../../pages/successPay/successPay?state=' + 1
					})
				}
			},
			//跳转订单详情
			goOrderDetail(e){
				console.log(e);
				let or = encodeURIComponent(JSON.stringify(e))
				uni.navigateTo({
					url:'../orderDetail/orderDetail?or='+or
				})
			},
			//去评价
			goEvaluate(e){
				let page_obj = encodeURIComponent(JSON.stringify(e))
				uni.navigateTo({
					url:'../goEvaluate/goEvaluate?page_obj='+page_obj
				})
			},
			//切换tab
			tabClick(item){
				console.log(item);
				orderList({order_status:item.index}).then(res=>{
					console.log('信息',res);
					this.order_list =res
					this.order_list.forEach(v=>{
						let datetime = v.reserve_time.replace("/",'-').split('+')
						v.reserve_time =`${datetime[0]}-${datetime[1]}  ${datetime[2]}` 
					})
				})
			},
			//获取全部订单
			getOrderInfo(){
				orderList({order_status:this.current}).then(res=>{
					this.order_list =res
					this.order_list.forEach(v=>{
						let datetime = v.reserve_time.replace("/",'-').split('+')
						v.reserve_time =`${datetime[0]}-${datetime[1]}  ${datetime[2]}` 
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>
